<% filter = user_filtering.filter %>
<%= tag.div class: "quick-filter",
      data: { controller: "dialog", action: "keydown.esc->dialog#close click@document->dialog#closeOnClickOutside", filter_show: filter.public_send("#{name}_window").present? } do %>
    <button class="btn input input--select flex-inline txt-x-small" data-action="click->dialog#open:stop">
      <span class="overflow-ellipsis">
        <%= "#{label} #{TimeWindowParser.human_name_for(filter.public_send(name))&.downcase}" %>
      </span>
    </button>

    <dialog class="events__popup popup panel flex-column align-start gap-half fill-white shadow"
      aria-label="Created…" aria-description="Created…"
      data-dialog-target="dialog" data-action="turbo:before-cache@document->dialog#close">
      <strong class="popup__title margin-block-start-half pad-inline-half"><%= label %>…</strong>
      <%= form_with url: cards_path, method: :get, class: "popup__list",
            data: { controller: "form" } do |form| %>
        <% filter.as_params.except(name).each do |key, value| %>
          <%= filter_hidden_field_tag key, value %>
        <% end %>

        <% TimeWindowParser::VALUES.each do |value| %>
          <div class="popup__btn btn">
            <%= form.radio_button name, value,
                  checked: filter.public_send(name) == value,
                  data: { action: "change->form#submit" } %>

            <%= form.label name, TimeWindowParser.human_name_for(value), value: value, class: "overflow-ellipsis" %>
            <%= icon_tag "check", class: "checked flex-item-justify-end" %>
          </div>
        <% end %>
      <% end %>
    </dialog>
<% end %>
